package org.demo;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;

public class ExcelUtil {
	public static void setCellString(XSSFRow hssfRow, char index, String val) {
		XSSFCell cell = hssfRow.getCell(index - 'A');
		if (cell == null) {

		} else {
			if(isNum(val)){
				cell.setCellType(XSSFCell.CELL_TYPE_NUMERIC);
				if(isIntValue(val)){
					cell.setCellValue(Long.valueOf(val));
				}else{
					cell.setCellValue(Double.valueOf(val));
				}
			}else{
				cell.setCellValue(val);
				cell.setCellType(XSSFCell.CELL_TYPE_STRING);
				//cell.setCellStyle(new XSSF);
			}
			
			
			
		}

	}
	public static boolean isNum(String value) {
		return value != null && value.matches("\\d+(.\\d+)?");
	}
    /**
	 * 判断字符串是否是整型(包括int,long,short)
	 * 
	 * @param value要判断的字符串
	 * @return
	 */
	public static boolean isIntValue(String value) {
		return value != null && value.matches("\\d+");
	}
}
